package com.ruoyi.crop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.crop.api.domain.CheckReport;
import com.ruoyi.crop.service.CheckReportService;
import com.ruoyi.crop.mapper.CheckReportMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86178
* @description 针对表【src_check_report(检测报告)】的数据库操作Service实现
* @createDate 2024-07-27 09:35:55
*/
@Service
public class CheckReportServiceImpl extends ServiceImpl<CheckReportMapper, CheckReport>
    implements CheckReportService{

    /**
     * 查询检测报告信息列表
     */
    @Override
    public List<CheckReport> selectCheckReportList(CheckReport checkReport) {
        return baseMapper.selectCheckReportList(checkReport);
    }

    /**
     * 校验质检报告名称唯一
     * @param checkReport
     * @return
     */
    @Override
    public boolean checkReportNameUnique(CheckReport checkReport) {
        LambdaQueryWrapper<CheckReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(checkReport.getReportName()),CheckReport::getReportName,checkReport.getReportName());
        CheckReport one = this.getOne(queryWrapper);
        if (StringUtils.isNotNull(one)){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 校验质检报告批次号唯一
     * @param checkReport
     * @return
     */
    @Override
    public boolean checkMaterialCodeUnique(CheckReport checkReport) {
        LambdaQueryWrapper<CheckReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(checkReport.getMaterialCode()),CheckReport::getMaterialCode,checkReport.getMaterialCode());
        CheckReport one = this.getOne(queryWrapper);
        if (StringUtils.isNotNull(one)){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}




